﻿@using DTcms.Common;
@{
    ViewBag.Title = "会员管理";
}
@section HeaderContent{
    <style type="text/css">
        .layui-table-view .layui-table[lay-size=lg] .layui-table-cell {
            height: 65px;
            line-height: 65px
        }
    </style>
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">会员管理</a> </li>
            <li><a href="javascript:;">充值记录</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a class="layui-btn icon-btn layui-btn-normal layui-btn-sm" href="../users/user_edit?action=@DTEnums.ActionEnum.Add"><i class="iconfont icon-close1"></i><span> 新增</span></a>
                            <a data-type="btnSms" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="fa fa-send"></i><span> 短信</span></a>
                            <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i><span> 删除</span></a>
                        </div>
                        <div class="menu-select">
                            <select class="select" lay-filter="btnSearch" name="ddlSiteId" url="/webapi/siteJson" selectValue="" promtion="所有站点"><option value="">所有站点...</option></select>
                            <select class="select" lay-filter="btnSearch" name="ddlGroupId" url="/webapi/groupJson" selectValue="" promtion="所有会员组"><option value="">所有会员组...</option></select>
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'user_name', width:'25%',templet:'#username'}">用户名</th>
                        <th lay-data="{field:'groupTitle'}">会员组</th>
                        <th lay-data="{field:'email'}">邮箱</th>
                        <th lay-data="{field:'mobile'}">手机号</th>
                        <th lay-data="{field:'amount',edit: 'text'}">余额</th>
                        <th lay-data="{field:'point',edit: 'text'}">积分</th>
                        <th lay-data="{field:'status',templet: '#status'}">状态</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="barDemo">
    <a href="../users/user_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs">修改</a>
</script>
<script type="text/html" id="username">
    <a href="../user_edit/index?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="user-avatar">
        {{#  if(d.avatar!=""){ }}
        <img width="64" height="64" src="{{d.avatar}}" />
        {{#  } else{ }}
        <i class="iconfont icon-user-full"></i>
        {{#  } }}
    </a>
    <div class="user-box">
        <h4><b>{{d.user_name}}</b> (昵称：{{d.nick_name}})</h4>
        <i>注册时间：{{d.reg_time}}</i>
        <span>
            <a class="amount" href="../users/amount_log?keywords={{d.user_name}}" title="消费记录"><i class="iconfont icon-count"></i></a>
            <a class="card" href="../users/recharge_list?keywords={{d.user_name}}" title="充值记录"><i class="iconfont icon-order"></i></a>
            <a class="point" href="../users/point_log?keywords={{d.user_name}}" title="积分记录"><i class="iconfont icon-star1"></i></a>
            <a class="msg" href="../users/message_list?keywords={{d.user_name}}" title="消息记录"><i class="iconfont icon-comment"></i></a>
            {{#  if(d.mobile!=""){ }}
            <a class="sms" href="javascript:;" lay-event="btnSms" title="发送手机短信通知"><i class="iconfont icon-mail"></i></a>
            {{#  } }}
        </span>
    </div>
</script>
<script type="text/html" id="status">
    {{# if(d.status == 0){ }}
    <span class="layui-btn layui-btn-normal layui-btn-xs">正常</span>
    {{#  } else if(d.status == 1){ }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">待验证</span>
    {{#  } else if(d.status == 2){ }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">待审核</span>
    {{#  } else if(d.status == 3){ }}
    <span class="layui-btn layui-btn-disabled layui-btn-xs">已禁用</span>
    {{# } }}
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['table', 'cascadeSelect', 'cmswh'], function () {
            var table = layui.table, form = layui.form, cascadeSelect = layui.cascadeSelect, cmswh = layui.cmswh, $ = layui.jquery;
            cascadeSelect.init('ddlSiteId', false);
            cascadeSelect.init('ddlGroupId', false);

            cmswh.dataBind('UserList');
            var fun = {
                btnDelete: function () {
                    cmswh.batOperate('UserDelete', 'id');
                },
                btnSms: function () {
                    var checkStatus = table.checkStatus('ltable'), data = checkStatus.data, ids = [];
                    data.forEach(function (n, i) {
                        ids.push(n.mobile);
                    });
                    if (ids.length == 0) {
                        layer.confirm("对不起，请选中您要操作的记录！", {
                            title: "提示",
                            btn: ['确定']
                        }, function (index) {
                            layer.close(index);
                        });
                        return false;
                    }
                    PostSMS(ids);
                },
                btnSearch: function () {
                    table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                }
            };
            //监听工具条
            table.on('tool(ltable)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'btnSms') {
                    PostSMS(data.mobile);
                }
            });
            form.on('select(btnSearch)', function (data) {
                var type = "btnSearch";
                fun[type] ? fun[type].call(this) : '';
            });
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                fun[type] ? fun[type].call(this) : '';
            });
            //监听单元格编辑
            table.on('edit(ltable)', function (obj) {
                var value = obj.value, data = obj.data, field = obj.field;
                cmswh.request("UserFieldSave?id=" + data.id + "&value=" + value + "&field=" + field, "POST");
            });
            /*拼接条件返回postdata*/
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var groupId = $("select[name=ddlGroupId]").val();
                var siteId = $("select[name=ddlSiteId]").val();
                var postdata = { keywords: keywords, group_id: groupId, site_id: siteId };
                return postdata;
            }
            //发送短信
            function PostSMS(mobile) {
                if (mobile == "") {
                    layer.confirm("对不起，手机号码不能为空！", {
                        title: "发送短信",
                        btn: ['确定']
                    }, function (index) {
                        layer.close(index);
                    });
                    return false;
                }
                layer.prompt({
                    title: '发送短信',
                    formType: 2,
                    skin: 'layui-layer-admin layui-layer-prompt',
                    shade: .1
                }, function (value, index, elem) {
                    var postData = { "mobiles": mobile, "content": value };
                    //发送AJAX请求
                    $.ajax({
                        type: "post",
                        url: "/admin_ajax/sms_message_post",
                        data: postData,
                        dataType: "json",
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert('尝试发送失败，错误信息：' + errorThrown, { icon: 5 });
                        },
                        success: function (data, textStatus) {
                            if (data.status == 1) {
                                layer.msg(data.msg, { time: 2000 }, function () { });
                            } else {
                                layer.alert('错误提示：' + data.msg, { icon: 5 });
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        });
    </script>
}